package main.string;

import main.string.utill.ItemLimitRuleVO;
import main.string.utill.JsonUtil;
import main.string.utill.ReplyDTO;
import org.junit.Test;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @create 2017-04-18 16:48
 **/
public class ObjectToJson3 {
	@Test
	public void test() throws Exception {
		ItemLimitRuleVO itemLimitRuleVO = new ItemLimitRuleVO();
		List<ItemLimitRuleVO> list = new ArrayList<ItemLimitRuleVO>();
		ItemLimitRuleVO itemLimitRuleVO1 = new ItemLimitRuleVO();
		itemLimitRuleVO1.setAgentGrade(1L);
		itemLimitRuleVO1.setPrice("300");


		ItemLimitRuleVO itemLimitRuleVO2 = new ItemLimitRuleVO();
		itemLimitRuleVO2.setAgentGrade(2L);
		itemLimitRuleVO2.setPrice("320");


		ItemLimitRuleVO itemLimitRuleVO3 = new ItemLimitRuleVO();
		itemLimitRuleVO3.setAgentGrade(3L);
		itemLimitRuleVO3.setPrice("330");


		ItemLimitRuleVO itemLimitRuleVO4 = new ItemLimitRuleVO();
		itemLimitRuleVO4.setAgentGrade(4L);
		itemLimitRuleVO4.setPrice("340");



		ItemLimitRuleVO itemLimitRuleVO5 = new ItemLimitRuleVO();
		itemLimitRuleVO5.setAgentGrade(5L);
		itemLimitRuleVO5.setPrice("350");


		list.add(itemLimitRuleVO1);
		list.add(itemLimitRuleVO2);
		list.add(itemLimitRuleVO3);
		list.add(itemLimitRuleVO4);
		list.add(itemLimitRuleVO5);
		itemLimitRuleVO.setLimitRuleList(list);
		itemLimitRuleVO.setSkuId(80L);
		System.out.println("@@@"+JsonUtil.toJson(itemLimitRuleVO));
	}



	@Test
	public void test2() throws Exception {
		String content = "{\"sku_id\":80,\"limit_rule_list\":[{\"price\":\"300\",\"agent_grade\":1},{\"price\":\"320\",\"agent_grade\":2},{\"price\":\"330\",\"agent_grade\":3},{\"price\":\"340\",\"agent_grade\":4},{\"price\":\"350\",\"agent_grade\":5}]}\n";
		Type type = new com.google.gson.reflect.TypeToken<ItemLimitRuleVO>() {
		}.getType();
		ItemLimitRuleVO itemLimitRuleVO = JsonUtil.parseJson(content,type);
		System.out.println(
				"agentLimitRuleVO...:" + JsonUtil.toJson(itemLimitRuleVO));
	}
	@Test
	public void test4() throws Exception {
		ItemLimitRuleVO itemLimitRuleVO = new ItemLimitRuleVO();
		List<ItemLimitRuleVO> list = new ArrayList<ItemLimitRuleVO>();
		ItemLimitRuleVO itemLimitRuleVO1 = new ItemLimitRuleVO();
		itemLimitRuleVO1.setAgentGrade(1L);
		itemLimitRuleVO1.setOrderMin("2");
		itemLimitRuleVO1.setDayMax("5");
		itemLimitRuleVO1.setWeekMax("20");
		itemLimitRuleVO1.setMonthMax("100");
		itemLimitRuleVO1.setRemark("备注");

//		ItemLimitRuleVO itemLimitRuleVO2 = new ItemLimitRuleVO();
//		itemLimitRuleVO2.setAgentGrade(2L);
//		//		itemLimitRuleVO2.setPrice("320");
//		itemLimitRuleVO2.setOrderMin("2");
//		itemLimitRuleVO2.setDayMax("5");
//		itemLimitRuleVO2.setWeekMax("20");
//		itemLimitRuleVO2.setMonthMax("100");
//
//		ItemLimitRuleVO itemLimitRuleVO3 = new ItemLimitRuleVO();
//		itemLimitRuleVO3.setAgentGrade(3L);
//		//		itemLimitRuleVO3.setPrice("330");
//		itemLimitRuleVO3.setOrderMin("2");
//		itemLimitRuleVO3.setDayMax("5");
//		itemLimitRuleVO3.setWeekMax("20");
//		itemLimitRuleVO3.setMonthMax("100");
//
//		ItemLimitRuleVO itemLimitRuleVO4 = new ItemLimitRuleVO();
//		itemLimitRuleVO4.setAgentGrade(4L);
//		//		itemLimitRuleVO4.setPrice("340");
//		itemLimitRuleVO4.setOrderMin("2");
//		itemLimitRuleVO4.setDayMax("5");
//		itemLimitRuleVO4.setWeekMax("20");
//		itemLimitRuleVO4.setMonthMax("100");
//
//
//		ItemLimitRuleVO itemLimitRuleVO5 = new ItemLimitRuleVO();
//		itemLimitRuleVO5.setAgentGrade(5L);
//		//		itemLimitRuleVO5.setPrice("350");
//		itemLimitRuleVO5.setOrderMin("2");
//		itemLimitRuleVO5.setDayMax("5");
//		itemLimitRuleVO5.setWeekMax("20");
//		itemLimitRuleVO5.setMonthMax("100");
//
		list.add(itemLimitRuleVO1);
//		list.add(itemLimitRuleVO2);
//		list.add(itemLimitRuleVO3);
//		list.add(itemLimitRuleVO4);
//		list.add(itemLimitRuleVO5);
		itemLimitRuleVO.setLimitRuleList(list);
		itemLimitRuleVO.setSkuId(80L);
		System.out.println("@@@"+JsonUtil.toJson(itemLimitRuleVO));
	}

	@Test
	public void test3() throws Exception {
		String str = "{\"sku_id\":80,\"limit_rule_list\":[{\"order_min\":\"2\",\"day_max\":\"5\",\"week_max\":\"20\",\"month_max\":\"100\",\"remark\":\"备注\",\"agent_grade\":1}]}";
		Type type = new com.google.gson.reflect.TypeToken<ItemLimitRuleVO>() {
		}.getType();
		ItemLimitRuleVO itemLimitRuleVO = JsonUtil.parseJson(str,type);
		System.out.println(
				"agentLimitRuleVO...:" + JsonUtil.toJson(itemLimitRuleVO));
	}

}
